package happens_before;

/**
 * @author juntao zhang
 */
public class InterruptionRule {
  private boolean sharedVariable=true;

  public void interruptTest() throws InterruptedException {
    Thread someThread = new Thread(() -> {
      long i = 0L;
      while (sharedVariable) {
          i++;
//        try {
//          System.out.println("sleep");
//          Thread.sleep(200);
//        } catch (InterruptedException e) {
//          // Is it here guaranteed that changes before interrupt are always visible here?
//          System.out.println("interupted "+sharedVariable);
//        }
      }
      System.out.println("end "+sharedVariable);
    });
    someThread.start();
    Thread.sleep(100);
    sharedVariable = false;
    Thread.sleep(2000);
//    someThread.interrupt();
  }

  public static void main(String[] args) throws InterruptedException {
    new InterruptionRule().interruptTest();
  }
}
